package cn.com.bluemoon.daps.api.sys.factory;

import cn.com.bluemoon.daps.api.sys.RemoteSystemInfoService;
import cn.com.bluemoon.daps.common.constant.ServiceNameConstants.DapsApiSystem;
import cn.com.bluemoon.daps.common.domain.ResultBean;
import cn.com.bluemoon.daps.common.enums.BmStatus;
import cn.com.bluemoon.daps.common.toolkit.FeignClientTools;
import cn.com.bluemoon.daps.system.dto.SystemInfoDto;
import cn.com.bluemoon.daps.system.entity.DapSystemInfo;
import cn.com.bluemoon.daps.system.vo.SimpleSysInfoVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Optional;

@Component
public class RemoteSystemInfoServiceFallbackFactory implements FallbackFactory<RemoteSystemInfoService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteSystemInfoServiceFallbackFactory.class);


    @Override
    public RemoteSystemInfoService create(Throwable throwable) {
        log.error("系统服务调用失败:{}", throwable.getMessage());
        return new RemoteSystemInfoService() {

            @Override
            public Page<SystemInfoDto> getSysInfoPage(Long current, Long pageSize, String keyword, BmStatus bmStatus) {
                return new Page<>();
            }

            @Override
            public ResultBean<DapSystemInfo> getSystemInfo(String sysId) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, DapsApiSystem.PROD_SERVICE, "获取系统信息失败");
            }

            @Override
            public ResultBean<List<DapSystemInfo>> getSystemInfoList(String ids) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, DapsApiSystem.PROD_SERVICE, "获取系统信息失败");
            }

            @Override
            public Optional<DapSystemInfo> getById(String sysId) {
                return Optional.empty();
            }

            @Override
            public ResultBean<Boolean> updateAuditStatusById(Integer auditStatus, String auditResultId, boolean updateAuditTime, String systemId) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, DapsApiSystem.PROD_SERVICE, "获取系统信息失败");
            }

            @Override
            public ResultBean<List<DapSystemInfo>> getSysInfos(String name) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, DapsApiSystem.PROD_SERVICE, "获取系统信息失败");
            }

            @Override
            public ResultBean<List<SimpleSysInfoVo>> getSystemInfosByUserIdAndType(String userId, Integer userType) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, DapsApiSystem.PROD_SERVICE, "工号获取用户相关系统信息失败");
            }

            @Override
            public ResultBean<List<SimpleSysInfoVo>> listByDbType(Integer dbType) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, DapsApiSystem.PROD_SERVICE, "数据库类型获取系统列表");
            }

            @Override
            public ResultBean<DapSystemInfo> getSysInfo(String name) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, DapsApiSystem.PROD_SERVICE, "获取系统失败");
            }

        };
    }
}
